package com.bsh.api;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bsh.api.Exception.ApiException;
import com.bsh.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bsh.utils.ApiMessage;

/**
 * 账单相关API
 * 
 * @author jane
 * @since 0.0.1
 * 
 */
@Controller
@RequestMapping(value = "/api/v1/bill", method = { RequestMethod.POST })
public class ApiBillController {
	@Autowired
	HttpServletRequest request;
	@Autowired
	HttpServletResponse response;
	@Autowired
	HttpSession session;
    @Autowired
	ApiBillService   apiBillService;
 
		
	@SuppressWarnings("finally")
	@RequestMapping(value = "/list/money", method = { RequestMethod.POST })
	@ResponseBody
	public ApiMessage billListMoney(@RequestParam(value="paramStr", required=true) String paramStr) {
		ApiMessage msg = new ApiMessage();
		try {
			JSONObject dto = (JSONObject) JSON.parse(paramStr);
			msg = apiBillService.billListMoney(dto);
		} catch (ApiException e) {
			msg.setCode(e.getCode());
			msg.setMessage(e.getMessage());
		} catch (Exception e) {
			msg = new ApiMessage("400", "请求失败");
			e.printStackTrace();
		} finally {
			return msg;
		}
	}
	
	
	@SuppressWarnings("finally")
	@RequestMapping(value = "/list/cloud", method = { RequestMethod.POST })
	@ResponseBody
	public ApiMessage billListCloud(@RequestParam(value="paramStr", required=true) String paramStr) {
		ApiMessage msg = new ApiMessage();
		try {
			JSONObject dto = (JSONObject) JSON.parse(paramStr);
			msg = apiBillService.billListCloud(dto);
		} catch (ApiException e) {
			msg.setCode(e.getCode());
			msg.setMessage(e.getMessage());
		} catch (Exception e) {
			msg = new ApiMessage("400", "请求失败");
			e.printStackTrace();
		} finally {
			return msg;
		}
	}

	
	
	 

}
